﻿using BookManageSystem;
using BookSystemLyn;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using web_search;

namespace User_subsystem
{
    public partial class FormAdmin : Form
    {
        public FormAdmin()
        {
            InitializeComponent();
        }
        public static string name;
        public static string id;
        public static string address;
        public static string phone;
        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void FormAdmin_Load(object sender, EventArgs e)
        {
            //显示管理员名称
            this.labeladmin.Text = $"欢迎您，管理员：{FormLogin.name}  {FormLogin.id}";
            //记录管理员各项属性
            DaoAdmin dao = new DaoAdmin();
            dao.connect();
            string sql = $"select  UserName,Address,ContactNum" +
                $" from [UserInfor] where UserID ='{FormLogin.id}' ";
            SqlDataReader reader = dao.read(sql);
            reader.Read();
            name = reader[0].ToString();
            id = FormLogin.id;
            address = reader[1].ToString();
            phone = reader[2].ToString();
            reader.Close();
            dao.DaoClose();
        }

        private void 管理员_Click(object sender, EventArgs e)
        {
           
        }

        private void 业务管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormAdminLookUser form = new FormAdminLookUser();
            form.ShowDialog();
        }

        private void 退出登录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("确认退出吗？", "消息", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                //退出
                this.Close();
            }
        }

        private void xToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormUpdatePwdUser form = new FormUpdatePwdUser();
            form.ShowDialog();
        }

        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
        }

        private void 修改用户密码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormUserselfmodify form = new FormUserselfmodify();
            form.ShowDialog();
        }

        private void 个人信息管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
           
        }

        private void 添加管理员ToolStripMenuItem_Click(object sender, EventArgs e)
        {         
        }

        private void 注销账号ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
        }

        private void 借阅记录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormAdminBorrowRec form = new FormAdminBorrowRec();
            form.ShowDialog();
        }

        private void 图书管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormBookInformationForAdministrator form = new FormBookInformationForAdministrator();
            form.ShowDialog();
        }

        private void 刷新页面ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //个人信息修改后要修改主页展示
            DaoAdmin dao = new DaoAdmin();
            dao.connect();

            string sql = $"select UserName from UserInfor where UserID={FormLogin.id}";
            SqlDataReader reader = dao.read(sql);
            if (reader.Read())
            {
                string newname = reader[0].ToString().Trim();
                this.labeladmin.Text = $"欢迎您，管理员：{newname}  {FormLogin.id}";
            }

            MessageBox.Show("刷新成功！", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
}
